<template>
  <el-dialog :visible.sync="dialogVisible" width="800px" :before-close="handleClose" :close-on-click-modal="false"
    append-to-body title="查看团队医生">
    <el-form :model="form" ref="formRef" label-width="140px"
      style="max-height: 580px; overflow: hidden;overflow-y: scroll;">
      <el-form-item label="团队医生" prop="members" :rules="[{ required: true, message: '请选择团队医生', trigger: 'blur' }]">
        <el-select v-model="form.members" clearable multiple filterable placeholder="请选择">
          <el-option v-for="item in doctorArr" :key="item.name" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="tx-c">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="confirm">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { ApigetTeamMember, ApigetDoctorList, ApiUpdateTeamMember } from "@/api/index.js";
export default {
  data() {
    return {
      dialogVisible: false,
      form: {},
      doctorArr: []
    }
  },
  methods: {

    show(row) {
      this.id = row.id
      this.dialogVisible = true
      this.getDocList()
      this.$nextTick(() => {
        this.getTeamDocList(row.id)
      })
    },
    handleClose() {
      this.dialogVisible = false
    },
    getTeamDocList(id) {
      this.teamDoc = []
      ApigetTeamMember(id).then(res => {
        res.data.forEach(item => {
          this.teamDoc.push(item.doctor_id)
        })
        this.form.members = this.teamDoc
      })
    },
    getDocList() {
      ApigetDoctorList({ page: 1, size: 999, type: '医生' }).then(res => {
        this.doctorArr = res.data
      })
    },
    //提交
    confirm() {
      ApiUpdateTeamMember(this.id, { members: this.form.members }).then(res => {
        if (res.code == 200) {
          this.$message.success("修改成功");
          this.handleClose()
          this.$emit("refresh");
        }
      })
    }
  }
}
</script>

<style>
</style>